package com.hairline.hairlinemarket.mapper;

import com.hairline.hairlinemarket.bean.MarketCart;
import com.hairline.hairlinemarket.bean.MarketCartExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

public interface MarketCartMapper {
    long countByExample(MarketCartExample example);

    int deleteByExample(MarketCartExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(MarketCart record);

    int insertSelective(MarketCart record);

    List<MarketCart> selectByExample(MarketCartExample example);

    MarketCart selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") MarketCart record, @Param("example") MarketCartExample example);

    int updateByExample(@Param("record") MarketCart record, @Param("example") MarketCartExample example);

    int updateByPrimaryKeySelective(MarketCart record);

    int updateByPrimaryKey(MarketCart record);

    // 查询总金额
    @Select("select sum(price*number) from market_cart where user_id = #{userId} and deleted=0;")
    BigDecimal selectGoodsAmount(Integer userId);
    // 查询总数量
    @Select("select sum(number) from market_cart where user_id = #{userId} and deleted=0;")
    BigDecimal selectGoodsCount(Integer userId);
    // 查询选择总金额
    @Select("select sum(price*number) from market_cart where user_id = #{userId} and checked=1 and deleted=0;")
    BigDecimal selectCheckedGoodsAmount(Integer userId);
    // 查询选择总数量
    @Select("select sum(number) from market_cart where user_id = #{userId} and checked = 1 and deleted = 0;")
    BigDecimal selectCheckedGoodsCount(Integer userId);

}